package user

/**
 * @Author       : Jinghua Fan
 * @Date         : 2021-11-28 20:17:14
 * @LastEditors  : Jinghua Fan
 * @LastEditTime : 2021-12-25 15:22:05
 * @Description  : 佛祖保佑,永无BUG
 */

import (
	"coupons/app/models"
	"coupons/pkg/password"
)

type User struct {
	models.BaseModel
	Name     string `gorm:"type:varchar(255);not null;unique" valid:"name"`
	Email    string `gorm:"type:varchar(255);unique" valid:"email"`
	Password string `gorm:"type:varchar(255)" valid:"password"`
	// gorm: "-" -- 设置 GORM 在读写时略过此字段
	PasswordConfirm string `gorm:"-" valid:"password_confirm"`
}

// ComparePassword 对比密码是否匹配
func (user *User) ComparePassword(_password string) bool {
	return password.CheckHash(_password, user.Password)
}
